package com.css.fxfzdpzs.modules.jcsj.controller;

import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.jcsj.entity.HistoricalEarthquake;
import com.css.fxfzdpzs.modules.jcsj.service.JcsjService;
import com.css.fxfzdpzs.modules.jcsj.vo.AreaVo;
import com.css.fxfzdpzs.modules.jcsj.vo.CompanyNumVo;
import com.css.fxfzdpzs.modules.jcsj.vo.EarthquakeNumVo;
import com.css.fxfzdpzs.modules.jcsj.vo.RoadVo;
import com.css.fxfzdpzs.modules.xczh.service.XczhService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 基础数据
 */
@Slf4j
@RestController
@RequestMapping("/jcsj")
public class JcsjController {
    @Autowired
    private XczhService xczhService;
    @Autowired
    private JcsjService jcsjService;

    //基础数据访问量统计    系统区分 0地震灾害现场调查与损失评估  1风险区划  2活动断层  3基础数据
    @GetMapping("/getVisitNum")
    public RestResponse getVisitNum(@RequestParam String system,@RequestParam(required = false) Integer num) {
        RestResponse restResponse = null;
        try {
            num= num==null?3:num;
            Map<String, Object> map = xczhService.getVisitNum(system,num);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询基础数据访问量统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省场地类型面积统计
    @GetMapping("/getArea")
    public RestResponse getArea(@RequestParam String category) {
        RestResponse restResponse = null;
        try {
            List<AreaVo> list = jcsjService.getArea(category);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省场地类型面积统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省道路长度统计
    @GetMapping("/getRoadLength")
    public RestResponse getLength(@RequestParam String category) {
        RestResponse restResponse = null;
        try {
            List<RoadVo> list = jcsjService.getLength(category);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省道路长度统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省 危化企业数量/加油站数量 统计
    //危化企业 传 2     加油站 传 4
    @GetMapping("/getCompanyNum")
    public RestResponse getCompanyNum(@RequestParam String type) {
        RestResponse restResponse = null;
        try {
            List<CompanyNumVo> list = jcsjService.getCompanyNum(type);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省数量统计失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //各省历史地震数量
    @GetMapping("/getEarthquakeNum")
    public RestResponse getEarthquakeNum(@RequestParam String category, @RequestParam String time) {
        RestResponse restResponse = null;
        try {
            List<EarthquakeNumVo> list = jcsjService.getEarthquakeNum(category, time);
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询各省历史地震数量失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //获取历史地震信息
    @GetMapping("/getEarthquakeData")
    public RestResponse getEarthquakeData() {
        RestResponse restResponse = null;
        try {
            List<HistoricalEarthquake> list = jcsjService.getEarthquakeData();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "获取历史地震信息失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

}
